Button improvements - #79
Conversation
Also add tooltip with the method signature, pretty print the method name ( doThing() -> Do Thing ), and make method buttons that do have parameters use any default parameters in the invocation foldout too.
|
Remade the pull request with only the intended commit. |
|
Do let me know if I can provide anything to help get this merged. Happy to update docs for it if you find the features useful. |
|
Thanks again for this contribution, and I’m sorry this PR also went without a decision for so long. I understand the appeal of invoking a parameterized method as a simple button using its default values. It is a useful idea, but I’m concerned that adding another invocation mode to Where possible, I would prefer to solve this using Alchemy’s existing building blocks. For example, optional inputs can be represented as non-serialized Inspector fields while the button method itself remains parameterless: [NonSerialized, ShowInInspector]
[LabelText("Specify Number of Foos")]
bool specifyNumberOfFoos;
[NonSerialized, ShowInInspector]
[ShowIf(nameof(specifyNumberOfFoos))]
[LabelText("Number of Foos")]
int numberOfFoos;
[Button]
[LabelText("More Method")]
void MoreMethod()
{
var value = specifyNumberOfFoos ? numberOfFoos : 50;
Debug.Log($"FooAmount: {value}");
}Although this requires a little more code, it makes the behavior explicit and allows existing attributes such as I can also see the convenience of generating a readable label with The remaining improvement - initializing parameter fields from their declared default values is useful, but equivalent behavior has since been implemented on the current Thanks again for taking the time to propose and implement these improvements. |
Pretty prints method name with

ObjectNames.NicifyVariableName(), and adds the method signature as a tooltip:Allows displaying a button with parameters as a simple button instead:

This will use default parameters when those are specified in the method signature.
Also fills default parameters when specified, for the normal invocation foldout:

Some other areas I'd like to improve and may get to:
I haven't tested this extremely thoroughly yet, and obviously there should be a documentation update alongside these changes.